package day08.test1;

import java.util.concurrent.*;

class Sum implements Callable {

    @Override
    public Integer call() throws Exception {
        int sum = 0;
        for (int i = 1; i <= 100; i++) {
            sum += i;
        }
        return sum;
    }
}

class PrintA extends Thread {
    @Override
    public void run() {
        for (int i = 0; i < 100; i++) {
            System.out.print("a");
        }
    }
}

class PrintB implements Runnable {

    @Override
    public void run() {
        for (int i = 0; i < 100; i++) {
            System.out.print("B");
        }
    }
}


public class test {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        Sum sum = new Sum();
        FutureTask<Integer> futureTask = new FutureTask<>(sum);
        Thread thread1 = new Thread(futureTask);

        PrintA printA = new PrintA();
        printA.start();

        PrintB printB = new PrintB();
        Thread thread2 = new Thread(printB);
        thread2.start();

        thread1.start();
        System.out.println("1到100的结果是:" + futureTask.get());
    }
}
